{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x = 1,cal= 2\n",
      "x = 2,cal= 5\n",
      "x = 0,cal= None\n"
     ]
    }
   ],
   "source": [
    "# pass占位符\n",
    "def cal(x,y):\n",
    "    if x > 1:\n",
    "        return x + y + 1\n",
    "    elif x == 0:\n",
    "        pass\n",
    "    else:\n",
    "        return x*y\n",
    "\n",
    "s1 = cal(1,2)\n",
    "print('x = 1,cal=',s1)\n",
    "s2 = cal(2,2)\n",
    "print('x = 2,cal=',s2)\n",
    "s0 = cal(0,2)\n",
    "print('x = 0,cal=',s0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('physics', 'chemistry', 1997, 2000)\n",
      "(1, 2, 3, 4, 5)\n",
      "('a', 'b', 'c', 'd')\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-11-846e49173b51>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtup2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      8\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtup3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0mtup1\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'123'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "# 元组用小括号定义，无法修改，可以理解为常量\n",
    "tup1 = ('physics', 'chemistry', 1997, 2000)\n",
    "tup2 = (1, 2, 3, 4, 5 )\n",
    "tup3 = \"a\", \"b\", \"c\", \"d\"\n",
    "\n",
    "print(tup1)\n",
    "print(tup2)\n",
    "print(tup3)\n",
    "tup1[0] = '123'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "list1[0]:  physics\n",
      "list2[1:5]:  [2, 3, 4, 5]\n",
      "list1[0]:  xxx\n"
     ]
    }
   ],
   "source": [
    "# 数组，元素不分类型\n",
    "list1 = ['physics', 'chemistry', 1997, 2000]\n",
    "list2 = [1, 2, 3, 4, 5, 6, 7 ]\n",
    " \n",
    "print(\"list1[0]: \", list1[0])\n",
    "print(\"list2[1:5]: \", list2[1:5])\n",
    "\n",
    "list1[0]='xxx'\n",
    "print(\"list1[0]: \", list1[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
